package me.ilich.piet.interpreter;

import me.ilich.piet.interpreter.elements.Block;
import me.ilich.piet.interpreter.elements.Codel;
import me.ilich.piet.interpreter.elements.Coordinate;
import me.ilich.piet.interpreter.elements.Program;
import junit.framework.TestCase;

public class ProgramTestCase extends TestCase {
	
	private Program mProgram;
	
	@Override
	protected void setUp() throws Exception {
		super.setUp();
		mProgram = new Program(1,1);
	}
	
	public void testA(){
		Codel codel = Codel.instance(Codel.GREEN, Codel.NORMAL);
		Coordinate coordinate = Coordinate.instance(0, 0);
		mProgram.setCodel(coordinate, codel);
		assertEquals(codel, mProgram.getCodel(coordinate));
	}
	
	public void testGetBlock1x1() {
		BlockFactory blockFactory = new BlockFactory();		
		Program prg = new Program(1, 1);
		prg.setCodel(0, 0, Codel.instance(Codel.GREEN, Codel.NORMAL));
		Block b = blockFactory.instanceBlock(Coordinate.instance(0, 0), prg);
		assertNotNull(b);
		assertEquals(b.getSize(), 1);
		assertEquals(b.getHue(), Block.GREEN);
		assertEquals(b.getLightness(), Block.NORMAL);
	}
	
	public void testGetBlock5x5() {
		BlockFactory blockFactory = new BlockFactory();
		Program prg = new Program(5, 5);
		prg.setCodel(0, 0, Codel.instance(Codel.GREEN, Codel.NORMAL));
		prg.setCodel(1, 0, Codel.instance(Codel.GREEN, Codel.NORMAL));
		prg.setCodel(2, 0, Codel.instance(Codel.GREEN, Codel.NORMAL));
		prg.setCodel(3, 0, Codel.instance(Codel.GREEN, Codel.NORMAL));
		prg.setCodel(4, 0, Codel.instance(Codel.GREEN, Codel.NORMAL));
		prg.setCodel(1, 1, Codel.instance(Codel.GREEN, Codel.NORMAL));
		prg.setCodel(1, 2, Codel.instance(Codel.GREEN, Codel.NORMAL));
		Block b = blockFactory.instanceBlock(Coordinate.instance(0, 0), prg);
		assertNotNull(b);
		assertEquals(b.getSize(), 7);
		assertEquals(b.getHue(), Block.GREEN);
		assertEquals(b.getLightness(), Block.NORMAL);
	}	

}
